package com.briup.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.briup.common.bean.TblCategory;
import com.briup.common.dao.TblCategoryMapper;
import com.briup.service.interfaces.TblCategoryService;

public class TblCategoryServiceImpl implements TblCategoryService {

	@Override
	public int insertCategoryByCodeAndName(SqlSession openSession, String code, String name) {
		int i = 0 ;
		TblCategoryMapper mapper = openSession.getMapper(TblCategoryMapper.class) ;
		i = mapper.insertCategoryByCodeAndName(code, name) ;
		return i ;
	}

	@Override
	public int deleteCategoryById(SqlSession openSession, String id) {
		// TODO Auto-generated method stub
		int i= 0;
		TblCategoryMapper mapper = openSession.getMapper(TblCategoryMapper.class) ;
		i= mapper.deleteCategoryById(id) ;		
		return i ;
	}

	@Override
	public List<TblCategory> selectCategorys(SqlSession openSession) {
		List<TblCategory> categories = new ArrayList<>() ;
		TblCategoryMapper mapper = openSession.getMapper(TblCategoryMapper.class) ;
		categories = mapper.selectCategorys() ;
		return categories ;
	}
	
	@Override
	public int updateCategoryById(SqlSession openSession, String code, String name,String id) {
		int i = 0 ;
		TblCategoryMapper mapper = openSession.getMapper(TblCategoryMapper.class) ;
		i = mapper.updateCategoryById(code, name,id) ;
		return i ;
	}
	

}
